/******************************************************************************
 *      Mestrado em Ciência da Computação - UFMS
 *		Redes de Computadores - Prof. Dr. Ronaldo Alves Ferreira
 *		Alunos: Geraldo Landre, Marcel Tolentino, Vinícius Bueno
 *****************************************************************************/
/* tcpkick.c - tcpkick */

#include "my_socket.h"
#include "tcpfms.h"
#include "tcb.h"
#include "tcp.h"

extern int tmset(int port, int portlen, void *msg, int time);
extern int tmleft(int port, void *msg);

/*------------------------------------------------------------------------
 *  tcpkick -  make sure we send a packet soon
 *------------------------------------------------------------------------
 */
int tcpkick(struct tcb *ptcb)
{
    int	tcbnum = ptcb->tcb_dvnum;	/* for MKEVENT() */
    void	*tv;

    tv = MKEVENT(SEND, tcbnum);
    if (ptcb->tcb_flags & TCBF_DELACK && !tmleft(thread_getport(output_thread), tv))
        tmset(thread_getport(output_thread), TCPQLEN, tv, TCP_ACKDELAY);
    else if (port_countmsg(thread_getport(output_thread)) < TCPQLEN)
         port_sendmsg(thread_getport(output_thread), (int)tv);	/* send now */
    return OK;
}
